package dfsketches.gr3d;

public class StaticProjector implements Projector {

	protected Matrix3D m;
	protected float k;
	protected int dx;
	protected int dy;
	
	public StaticProjector(float k, int dx, int dy, Matrix3D m) {
		this.m = m;
		this.k = -k;
		this.dx = dx;
		this.dy = dy;
	}
	
	public void transform(Triangle t) {
		t.apply(m);
	}
	
	@Override
	public void project(Triangle t) {
		project(t.a);
		project(t.b);
		project(t.c);
	}

	@Override
	public float getUnscaledX(float x) {
		return x / k + 0.5f;
	}

	@Override
	public float getUnscaledY(float y) {
		return y / k + 0.5f;
	}

	public void project(Vertex v) {
		float _z = 1f / (v.z);
		v.px = (int) (k * v.x * _z) + dx;
		v.py = (int) (k * v.y * _z) + dy;
	}
	
	@Override
	public Matrix3D getMatrix() {
		return m;
	}

}